package com.kevin.spider.zookeeper.config;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author kevin
 */
@Configuration
public class ZooKeeperConfig {
    @Bean
    public CuratorFramework curatorFramework() {
        return CuratorFrameworkFactory.builder()
                // 可选，用于创建命名空间隔离环境
                //.namespace("myapp")
                .connectString("wsl.localhost.com:2181")
                .sessionTimeoutMs(5000)
                .connectionTimeoutMs(3000)
                // 重试策略
                .retryPolicy(new ExponentialBackoffRetry(1000, 3))
                .build();
    }
}
